<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="Pragma" content="no-cache" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
		<script src="js/jquery-2.0.0.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			td,
			th,
			li {
				vertical-align: middle;
				text-align: center;
			}
			
			td {
				background-color: #f0f0f0;
			}
			
			.meigou {
				display: block;
				width: 14px;
				height: 14px;
				margin: auto;
				background-image: url(img/list-view_4e60b0c.png);
				background-position: -8px -12px;
			}
			
			.gou {
				background-position: -40px -12px;
			}
		</style>
	</head>

	<body>
		<div class="container">
			<div class="row" style="border-bottom: 1px solid #000;">
				<img class="img-responsive col-lg-4" src="img/logo.png.jpg" />
			</div>
			<div class="row">
				<h3 class="col-lg-12 text-center">教师授课满意度问卷调查表</h3>
			</div>
			<div class="row">
				<h4 class="col-lg-12" style="text-align: right;"><small> 编号：XHQ-YNKM-QR-7.5-13</small></h4>
			</div>
			<div>
				<form action="savesurvey" method="post" accept-charset="UTF-8">
					<div class="row">
						<ul class="list-group list-inline">
							<li class="col-lg-3">
								<div class="input-group">
									<input type="text" class="form-control" id="majortext" />
									<div class="input-group-btn">
										<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">专业<span class="caret"></span></button>
										<ul class="dropdown-menu pull-right" id="major">
										</ul>
											<input type='hidden' name='major_id' id='majorhidden'/>
									</div>
								</div>
							</li>

							<li class="col-lg-3">
								<div class="input-group">
									<input type="text" class="form-control" id="coursestext" />
									<div class="input-group-btn">
										<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">课程<span class="caret"></span></button>
										<ul class="dropdown-menu pull-right" id="courses">
										</ul>
											<input type='hidden' name='courses_Id' id='courseshidden'/>
									</div>
								</div>
							</li>

							<li class="col-lg-3">
								<div class="input-group">
									<input type="text" class="form-control" id="teachertext" />
									<div class="input-group-btn">
										<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">教师<span class="caret"></span></button>
										<ul class="dropdown-menu pull-right" id="teacher">
										</ul>
										 <input type='hidden' name='teacher_Id' id='teacherhidden'/>
									</div>
								</div>
							</li>

							<li class="col-lg-3"><input type="text" class="form-control text-center" id="time" readonly="readonly" name="date" /></li>
						</ul>
					</div>
					<div class="row" style="margin-top: 20px;">
						<table class="table table-bordered" >
							<tr>
								<th rowspan="3" style="vertical-align: middle;">序号</th>
								<th rowspan="3" style="vertical-align: middle;">调查项</th>
								<th rowspan="3" style="vertical-align: middle;">调查细节项目</th>
								<th colspan="5">
									满意度得分
								</th>
							</tr>
							<tr>
								<td>很满意</td>
								<td>满意</td>
								<td>一般</td>
								<td>不满意</td>
								<td>很不满意</td>
							</tr>
							<tr>
								<td>5分</td>
								<td>4分</td>
								<td>3分</td>
								<td>2分</td>
								<td>1分</td>
							</tr>
							
							<tr id="tab">
							<td colspan='2'>建议</td>
						     <td colspan='6'>
						     	<textarea class='col-lg-12' style='border: 0px;' name='suggest' value='123'></textarea>
						     </td>
							</tr>
						</table>
					</div>
					<input class="btn-primary btn-lg" type="submit" value="提交评分" />
				</form>
			</div>
			<div>
				<p>备注： 1.请在满意程度分项内选择一项打“√”； 2.本问卷属无记名打分，为进一步提高我院教学质量，检查教师授课水平、教学成效，请您本着公平、公正的态度认真、属实填写。3.本问卷不选默认5分。
				</p>
			</div>
		</div>
		<script type="text/javascript">
			(function() { //时间
				var date = new Date();
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				var day = date.getDate();
				var hours = date.getHours();
				var minutes = date.getMinutes();
				var seconds = date.getSeconds();
				$("#time").attr("value", year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds);
			})();

			$.ajax({ //专业 
				type: "get",
				url: "getmajor",
				success: function(data) {
					$.each(data, function(index, mj) { //da是需要遍历的对象， index遍历出来有几个（0，1，2，3），mj是没一个的值（UI,建筑，营销..）
						$("#major").append("<li><a class='majors'><input type='hidden' value='"+mj.id+"'/>" + mj.name + "</a></li>");
					});
					downcontent();
				}
			});
			
		    var major_Id;   //把major_Id保存在#majorhidden这个input里面
            var courses_Id; 
           	var teacher_Id;
			function downcontent() { //点击major后coruses然后teacher也联动的方法
				var s; //点击的a标签的内容
				$(".majors").click(function() {
					s = $(this).text();    //给major文本框赋值，当前点击对象是a标签
			    	major_Id=$(this).children().val();  //获取major_Id
//					alert("major_Id:"+major_Id);
			    
					$("#majortext").val(s); //点击下拉框内容把值付给major文本框
					
					$.ajax({
						type: "get",
						url: "getcourse/" + major_Id,
						success: function(data) {
							$("#courses").html("");
							$.each(data, function(index, cs) {
								$("#courses").append("<li><a class='cours'>" + cs.name + "<input type='hidden' value='" + cs.id + "'/></a></li>");
							});
							$("#coursestext").val(data[0].name); //把课程下拉框的第一个课程添加到文本框
							courses_Id=data[0].id;
//							$("#courseshidden").val(courses_Id);  //把课程下拉框的第一个课程的ID添加#courseshidden保存起来
//                            alert("courses_id:"+courses_Id);
							$.ajax({                                //根据课程老师也变动
								type: "get",
								url: "getteacher/" + courses_Id,
								success: function(data) {
									$("#teacher").html("");
									$.each(data, function(index, tc) {
										$("#teacher").append("<li><a class='teach'>" + tc.name + "<input type='hidden' value='" + tc.id + "'/></a></li>");
									});
									 $("#teachertext").val(data[0].name);  //把教师下拉框的第一个教师添加到文本框
									 teacher_Id=data[0].id;
//									$("#teacherhidden").val(teacher_Id);  //把教师下拉框的第一个教师的ID添加#teacherhidden保存起来
//									alert("teacher_Id:"+da2[0].id);   
									downTeacher();
								}
							});
							downcourse();
						}
					});
				});
			}

			function downcourse() { //点击coruses后teacher联动的方法  
				var x;
				$(".cours").click(function() { //下拉课程框填值得方法
					x = $(this).text();
					courses_Id=$(this).children().val();   //courses_Id等于当前点击的下拉课程框里的a标签里的input的val
					$("#coursestext").val(x); //点击下拉框内容把值付给文本框
					$("#courseshidden").val(courses_Id);
					
//					alert("courses_Id:"+courses_Id);
					$.ajax({
						type: "get",
						url: "getteacher/" + courses_Id,
						success: function(data) {
							$("#teacher").html("");
							$.each(data, function(index, tc) {
								$("#teacher").append("<li><a class='teach'>" + tc.name + "<input type='hidden' value='" + tc.id + "'/></a></li>");
							});
							$("#teachertext").val(data[0].name);    //把教师下拉框的第一个教师添加到文本框
							 teacher_Id=data[0].id;
//							$("#teacherhidden").val(teacher_Id);    //把教师下拉框的第一个教师的ID添加#teacherhidden保存起来
//							alert("teacher_Id:"+da[0].id);
							downTeacher();
						}
					});

				});
			}

			function downTeacher() {
				var y;
				$(".teach").click(function() { //下拉课程框填值得方法
					y = $(this).text();
					teacher_Id=$(this).children().val();   //teacher_Id等于当前点击的下拉教师框里的a标签里的input的val
					$("#teachertext").val(y); //点击下拉框内容把值付给文本框 
					
//					alert("teacher_Id:"+teacher_Id);
				});
			}

			$.ajax({ //填充表格内容
				type: "get",
				url: "getsurveyitems",
				success: function(data) {
					var html="";
					var idx=0;
					$.each(data, function(index, si) {						
						html+="<tr><td rowspan=" + (si.conts.length + 1) + ">" + si.id + "</td>" +
							  "<td rowspan=" + (si.conts.length + 1) + ">" + si.name + "</td></tr>";
					
						$.each(si.conts, function(i, cont) { //si.contents内容细节
							html+="<tr><input type='hidden' class='xuan' name='score' value='5'/>"+
							"<input type='hidden' name='content_id' value='"+cont.id+"'/>"+
								"<td>" + cont.name + "</td>" +
								"<td class='sele'><span class='meigou' score='5'></span></td>" +
								"<td class='sele'><span class='meigou' score='4'></span></td>" +
								"<td class='sele'><span class='meigou' score='3'></span></td>" +
								"<td class='sele'><span class='meigou' score='2'></span></td>" +
								"<td class='sele'><span class='meigou' score='1'></span></td></tr>";
								idx++;
						});
					});
					$("#tab").before(html);
					 changegou();
					
				}

			});


			function changegou() { //点击没勾换有勾图片
				$(".sele").click(
					function(e) {
						var x; //保存score的值
						var rowid;
						var ele = e.target || e.srcElement; //ele是点击对象 
						$(ele).parents().children(".sele").children(".meigou").removeClass("gou"); //
						$(ele).children(".meigou").addClass("gou"); //用户点击的是格子
						$(ele).addClass("gou"); //用户点击的是没打勾的图片

						if(ele.tagName == "SPAN") { //如果点击的是span()
							x = $(ele).attr("score");
						} else {
							x = $(ele).children(".meigou").attr("score");
						}
						$(ele).parents("tr").children(".xuan").val(x); //把x付给点击对象的"tr"父亲下的'.xuan'的input的value

					});				
		     	panduan();
			};
                    
                             
			function panduan() {
				$("input[type=submit]").click(function() { //提交判断 
                   $("#majorhidden").val(major_Id);
                   $("#courseshidden").val(courses_Id);  //把课程下拉框的第一个课程的ID添加#courseshidden保存起来
                   $("#teacherhidden").val(teacher_Id);    //把教师下拉框的点击的教师的ID添加#teacherhidden保存起来
// 					alert("imjor:"+$("#majorhidden").val()+",c:"+$("#courseshidden").val()+",t:"+$("#teacherhidden").val());
					if(confirm("您是否确认提交？")) {
						if($("#majortext").val() == "") {
							alert("你专业没选");
							return false;		
						}
					} else {
						return false;
					}
				});
			};
		</script>
	</body>

</html>